fn removeAllModifiers objArray = 
(
	undo "OS3D Remove All Modifiers" on

	(
		for item in objArray do
		(
			cc = item.modifiers.count
			while cc>0 do
			(
			deleteModifier item cc
				cc -= 1
			)
		)
	)
)
fn SetMaterial InObject objArray = 
(
	undo "OS3D Set Material on selection" on
	(
		for item in objArray do
		(
			try (item.material = InObject.material)
			catch(print ("Could not set material on:" + item.name))
		)
	)
	
)
fn copyModifiers InObject objArray = 
(
	undo "OS3D Set Modifiers on selection" on
	(
	numMods = InObject.modifiers.count
	if numMods != 0 then
	(
		for item in objArray do
		(
			test = numMods
			if item.modifiers.count == 0 then (run = true) 
			else 
			(
				DispMessage = "The following item: " + item.name + "\nalready has modifiers on it, do you still want to apply the modifiers to this?"
				if querybox DispMessage then run = true else run = false
			)
			
			if run then
			(
			while test > 0 do
					(
					--print test
				try 
					(
					tmp = copy InObject.modifiers[test]
					-- print tmp
					addModifier Item tmp
					)
				catch
					(
					print "something didnt work when applying the following modifier"
					)
			test -=1
					)
			)
			
		)
	)
	else (print "no modifiers")
	)
)

rollout OS3DCopyMaterialModifiers "OS3D.se Copy materials and modifiers" width:272 height:118
(
	local debug = false
	local InputObject
	label lbl1 "Copy from" pos:[8,8] width:96 height:16
	button btnPasteMaterial "Paste Material to selection" pos:[128,28] width:136 height:24 toolTip:"Paste Material to selection"
	button btnPasteModifiers "Paste Modifers to selection" pos:[128,56] width:136 height:24 toolTip:"Paste Modifiers to selection"
	label lbl2 "Copy to" pos:[128,8] width:96 height:16
	button btnPasteMatAndMod "Paste Both to selection" pos:[128,84] width:136 height:24 toolTip:"Paste Both Material and Modifiers to selection"
	button btnFromObj "Select from object" pos:[6,28] width:114 height:24 toolTip:"Select object to copy modifiers and material from"
	--label lbl3 "OS3D.se Single copy material and modiers. v0.1" pos:[8,3] width:256 height:16
	
	button btnRemoveModifiers "Remove modifiers" pos:[6,84] width:114 height:24 toolTip:"Remove all modifiers on selection"
	label lbl8 "Delete modifiers" pos:[7,66] width:95 height:13
	
	
	on OS3DCopyMaterialModifiers open do
	(
	escapeEnabled = true
	)
	on btnPasteMaterial pressed do
	(
	selArray = selection as array
		if inputObject != undefined and selArray != undefined then
		(
			SetMaterial inputObject selArray
			)
	)
	on btnPasteModifiers pressed do
	(
		selArray = selection as array
		if inputObject != undefined and selArray != undefined then
		(
			copyModifiers inputObject selArray
		)
	)
	on btnPasteMatAndMod pressed do
	(
		selArray = selection as array
		if inputObject != undefined and selArray != undefined then
		(
			undo "OS3D Set Material and Modifiers on selection" on
			(
			SetMaterial inputObject selArray
			copyModifiers inputObject selArray
			)
		)
	
	
	)
	on btnFromObj pressed do
	(
		InputObject = pickobject()
		if InputObject != undefined do
		(
			btnFromObj.caption = InputObject.name
		)
	)
	on btnRemoveModifiers pressed do
	(
		selArray = selection as array
		if selArray != undefined then
			(
			removeAllModifiers selArray
			)
	)
)
createdialog OS3DCopyMaterialModifiers